feat: make BedrockModel._format_request and _convert_non_streaming_to…#2315
feat: make BedrockModel._format_request and _convert_non_streaming_to…#2315celealramos wants to merge 1 commit into
Conversation
9d1ae79 to
078434b
Compare
| """Format a Bedrock converse stream request. | ||
|
|
||
| .. deprecated:: | ||
| Use :meth:`format_request` instead. This will be removed in September 2026. |
There was a problem hiding this comment.
Don't call out a specific date; it's very subject to change.
| Returns: | ||
| A Bedrock converse stream request. | ||
| """ | ||
| with warnings.catch_warnings(): |
There was a problem hiding this comment.
The flow is a little odd right now; could we switch to:
format_requestis the entry point and what the model calls internallyformat_requestchecks if_format_requestis overridden; if it is it emits a warning and calls it, otherwise it invokes_format_request_impl(which is the default implementation) which calls_format_request
There was a problem hiding this comment.
I think we're also okay breaking users of _ as well given that it's marked as private.
That's what we went with for #2370
There was a problem hiding this comment.
Got it - if we're okay breaking users of _ as it is private then we can go ahead and make the switch from private to public from the getgo
| tool_specs: list[ToolSpec] | None = None, | ||
| system_prompt_content: list[SystemContentBlock] | None = None, | ||
| tool_choice: ToolChoice | None = None, | ||
| ) -> dict[str, Any]: |
There was a problem hiding this comment.
The changes in https://github.com/strands-agents/sdk-python/pull/2093/changes#r3306308887 is an example of an additive parameter FWIW
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…_streaming public
078434b to
37716b9
Compare
…_streaming public
Description
Users building custom Bedrock integrations need to format requests and convert non-streaming responses outside of the standard stream() flow. For example, to inspect or modify the request before sending, or to integrate with custom invocation pipelines. Currently these capabilities are only available through private methods (_format_request, _convert_non_streaming_to_streaming), making them fragile to depend on and inconsistent with other providers (Anthropic, Mistral, Ollama, Writer) that already expose public format_request.
Public API Changes
BedrockModel now exposes two public methods that delegate to the existing private implementations:
Before: rely on private API (fragile, undocumented)
model = BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0")
request = model._format_request(messages, tool_specs)
events = model._convert_non_streaming_to_streaming(response)
After: stable public API
model = BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0")
request = model.format_request(messages, tool_specs)
events = model.convert_non_streaming_to_streaming(response)
The private methods now emit a DeprecationWarning when called directly, with removal planned for September 2026. Internal call sites continue dispatching through the private methods (with warnings suppressed) so subclass overrides are honored without behavioral changes.
Related Issues
#2308
Documentation PR
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.